import { _decorator, Component, Node, v3, tween } from 'cc';
import { GameData } from './GameData';
const { ccclass, property } = _decorator;
import { Util } from './Util';
const gameData = GameData.getInstance()
@ccclass('Sun')
export class Sun extends Component {
    @property(Node)
    sunChild = null;
    moveSpeed = 1 // 下落的速度
    start() {
        this.node.on(Node.EventType.TOUCH_START, () => {
            gameData.setSunEnergy(50);
            this.node.destroy()
        })
    }

    update(deltaTime: number) {
        this.sunChild.angle += 1;
    }
    drop(){
        // 随机掉落到一个位置
        const targetPosY = Util.getRandomOpen(-300, 100)
        let that = this
        function move(){
            that.node.setPosition(v3(that.node.position.x, that.node.position.y - 1, 0));
            if(that.node.position.y < targetPosY){
                that.unschedule(move);
                that.scheduleOnce(() => {
                    that.node.destroy()
                }, 5)
            }
        }
        this.schedule(move, 1 / 60)
    }
}

